package com.test.burnincash.activity_fragment_burnin.loan_burnin;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;

import com.test.burnincash.bean_burnin.user_info_burnin.LoanApplyDetailInfo_burnin;
import com.test.burnincash.constant_burnin.Constant_burnin;
import com.test.burnincash.util_burnin.StringUtil_burnin;
import com.test.burnincash.util_burnin.ThreadUtil_burnin;
import com.test.burnincash.util_burnin.helper_burnin.UserInfoHelper_burnin;
import com.test.burnincash.util_burnin.http_burnin.HttpManager_burnin;
import com.test.burnincash.view_burnin.widget_burnin.TitleView_burnin;
import com.test.burnincash.R;
import com.test.burnincash.activity_fragment_burnin.base_burnin.BaseLoanActivity_burnin;


public class LoanApplyActivity_burnin extends BaseLoanActivity_burnin {

    private TextView loanAmountTv, loanAmountTv1, loanAmountTv2;
    private TextView loanTermTv, disburseAmountTv, serviceFeeTv1, repaymentAmountTv,
            interestTv, serviceFeeTv2, overduePenaltyInterestTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loan_apply_burnin);
        init();
    }

    private void init(){
        TitleView_burnin titleView = findViewById(R.id.activity_loan_apply_view_title);
        setBackBtn_burnin(titleView.getBackIb());

        loanAmountTv = findViewById(R.id.activity_loan_apply_tv_loan_amount);
        loanAmountTv1 = findViewById(R.id.activity_loan_apply_tv_loan_amount_1);
        loanAmountTv2 = findViewById(R.id.activity_loan_apply_tv_loan_amount_2);
        loanTermTv = findViewById(R.id.activity_loan_apply_tv_loan_term);
        disburseAmountTv = findViewById(R.id.activity_loan_apply_tv_disburse_amount);
        serviceFeeTv1 = findViewById(R.id.activity_loan_apply_tv_service_fee_1);
        repaymentAmountTv = findViewById(R.id.activity_loan_apply_tv_repayment_amount);
        interestTv = findViewById(R.id.activity_loan_apply_tv_interest);
        serviceFeeTv2 = findViewById(R.id.activity_loan_apply_tv_service_fee_2);
        overduePenaltyInterestTv = findViewById(R.id.activity_loan_apply_tv_overdue_penalty_interest);

        findViewById(R.id.activity_loan_apply_layout_apply).setOnClickListener(v ->
            ThreadUtil_burnin.getInstance().runOnChildThread(() -> {
                HttpManager_burnin.getInstance().saveUserBuriedPoint((this.getClass().getSimpleName()+"_CLICK").toUpperCase());
                
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                HttpManager_burnin.getInstance().loanApply();
            }));

    }

    @Override
    protected void onResume() {
        super.onResume();
        HttpManager_burnin.getInstance().requestLoanApplyDetail();
    }

    @SuppressLint("SetTextI18n")
    public void onLoanApplyDetailResponse(){

        //货币单位
        String moneyUnit = StringUtil_burnin.getSafeString(Constant_burnin.Money_Unit_Nigeria).toUpperCase();

        if (UserInfoHelper_burnin.getInstance().getToken().equalsIgnoreCase("c5469366490489f2bf275f16903cf90a")){
            loanAmountTv.setText(moneyUnit+" 300000");
            loanAmountTv1.setText("300000 "+moneyUnit);
            loanAmountTv2.setText("300000 "+moneyUnit);
            loanTermTv.setText("365 "+getString(R.string.word_days));

            disburseAmountTv.setText("300000 "+moneyUnit);
            serviceFeeTv1.setText("0 "+moneyUnit);
            serviceFeeTv2.setText("0 "+moneyUnit);
            repaymentAmountTv.setText("372000 "+moneyUnit);
            interestTv.setText("72000 "+moneyUnit);

            overduePenaltyInterestTv.setText("3" + getString(R.string.activity_loan_apply_rate_suffix));
            return;
        }

        loanAmountTv.setText(moneyUnit+" "+ LoanApplyDetailInfo_burnin.getInstance().getAmount());
        loanAmountTv1.setText(LoanApplyDetailInfo_burnin.getInstance().getAmount()+" "+moneyUnit);
        loanAmountTv2.setText(LoanApplyDetailInfo_burnin.getInstance().getAmount()+" "+moneyUnit);
        loanTermTv.setText(LoanApplyDetailInfo_burnin.getInstance().getDays()+" "+getString(R.string.word_days));

        disburseAmountTv.setText(LoanApplyDetailInfo_burnin.getInstance().getRealAmount()+" "+moneyUnit);
        serviceFeeTv1.setText(LoanApplyDetailInfo_burnin.getInstance().getProcessingFee()+" "+moneyUnit);
        serviceFeeTv2.setText(LoanApplyDetailInfo_burnin.getInstance().getRepayProFee()+" "+moneyUnit);
        repaymentAmountTv.setText(LoanApplyDetailInfo_burnin.getInstance().getRepayAmount()+" "+moneyUnit);
        interestTv.setText(LoanApplyDetailInfo_burnin.getInstance().getInterest()+" "+moneyUnit);

        String overduePenaltyInterest = (StringUtil_burnin.safeParseDouble(LoanApplyDetailInfo_burnin.getInstance().getOverdueRate())*100) + getString(R.string.activity_loan_apply_rate_suffix);
        overduePenaltyInterestTv.setText(overduePenaltyInterest);

    }

    public void onLoanApplyResponse(){
        HttpManager_burnin.getInstance().requestUserProcess();
    }
}